﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.1f1
 *Date:           2019-03-23
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
namespace IFramework
{
	public class ProjectInfo
	{
        public static ProjectSetting projectSetting;
        [InitializeOnLoadMethod]
        private static void LoadProjectInfo()
        {
            string[] guids = AssetDatabase.FindAssets("t:ProjectSettingSto", new string[] { @"Assets" });
            List<ProjectSettingSto> stolist = new List<ProjectSettingSto>();
            foreach (var item in guids)
            {
                string path = AssetDatabase.GUIDToAssetPath(item);
                stolist.Add( AssetDatabase.LoadAssetAtPath<ProjectSettingSto>(path));
            }
            if (stolist.Count == 0) 
            {
                CreateNewSto();
            }
            else
            {
                if (stolist.Count > 1)
                {
                    for (int i = 1; i < stolist.Count; i++)
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(stolist[i]));
                    }
                }
                if (!AssetDatabase.GetAssetPath(stolist[0]).Equals(ProjectSettingStoPath))
                {
                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(stolist[0]));
                    CreateNewSto();
                }
                else 
                {
                    projectSetting = stolist[0].projectSetting;
                }
            }
        }
        public static void CreateNewSto()
        {
            ScriptableObj.Create<ProjectSettingSto>(ProjectSettingStoPath);
            projectSetting = ScriptableObj.Load<ProjectSettingSto>(ProjectSettingStoPath).projectSetting;
        }
        public static string ProjectSettingStoPath = FrameWorkInfo.GetFrameWorkEditorPath().CombinePath("ProjectSettingSto.asset").ToRegularPath(); 

    }
}
